package com.hepinghospital.user.ui.activity.prescription;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.hepinghospital.user.R;
import com.hepinghospital.user.base.BaseActivity;
import com.hepinghospital.user.util.ToastUtil;
import com.rest.business.RestProxy;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import jz.joyoung.robot.util.UtilString;

/**
 * @time 2021/4/15 10:39
 */

public class AddExpressActivity extends BaseActivity {


    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.edt_name)
    EditText edtName;
    @BindView(R.id.edt_id_card)
    EditText edtIdCard;
    @BindView(R.id.tv_confirm)
    TextView tvConfirm;
    String prescriptionId, status;

    @Override
    protected int getLayoutResource() {
        return R.layout.aty_add_express;
    }

    @Override
    protected void initData() {
        prescriptionId = getIntent().getStringExtra("prescriptionId");
        status = getIntent().getStringExtra("status");

    }

    @Override
    protected void initViews() {
        tvTitle.setText("录入快递单");

    }


    @OnClick({R.id.tv_confirm})
    public void onViewClicked(View view) {
        if (view.getId() == R.id.tv_confirm) {
            updatePrescriptionStatus();

        }
    }


    private void updatePrescriptionStatus() {
        String name = edtName.getText().toString().trim();
        String idNumber = edtIdCard.getText().toString().trim();
        if (UtilString.isEmpty(name)) {
            ToastUtil.showToastCenter(mContext, "请录入快递公司名称");
            return;
        }
        if (UtilString.isEmpty(idNumber)) {
            ToastUtil.showToastCenter(mContext, "请录入回寄的快递单号");
            return;
        }


        try {
            showLoadingDialog(mContext);
            Map<String, Object> map = new HashMap<>();
            map.put("id", prescriptionId);
            map.put("status", "10");
            map.put("backWaybillNo", idNumber);

            RestProxy.getInstance().updatePrescriptionStatus(map, new Observer<Boolean>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(Boolean s) {
                    dismissLoadingDialog();
                    if(s) finish();
                }

                @Override
                public void onError(Throwable e) {
                    dismissLoadingDialog();
                    ToastUtil.onError(mContext, e);
                }

                @Override
                public void onComplete() {
                    dismissLoadingDialog();
                }
            });
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
